<template>
    <div id=form>
            <span>手机号码</span>
            <input v-model="name" type="tel" title="请输入用户名"  placeholder="请输入用户名" required autofocus><br/>
            <span>密码</span>
            <input v-model="pwd" type="password" placeholder="请输入密码"  required><br/>
            <button @click="register" >同意协议并注册</button><br/>
            <img class="ftimg" src="../assets/注册.png">
    </div>
</template>
<style src="../style/init.css" scoped>

</style>
<script>
export default {
    data:function(){
        return{
            name:"",
            pwd:"",
        }
    },
    methods:{
        register:function(){
            var user={name:this.name,pwd:this.pwd}
            this.$store.commit('queryuser',user)
            var mess=this.$store.state.mess
            if(mess=='f'){
                this.$store.commit('reg',user)
                alert("注册成功，将为你自动登录")
                sessionStorage.username=this.name
                this.$router.replace("/");//避免后退
            }
            else{
                alert("用户名已存在")
            }
        },
    }
}
</script>